package com.ourhealth.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import redis.clients.jedis.JedisPool;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor{
    @Autowired
    private JedisPool jedisPool;


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler) throws Exception {
        //获取页面携带的Token
        String token = request.getHeader("token");
        //通过token查看是否存在此用户
        String s = null;
        try {
            s = jedisPool.getResource().get(token);
            if (s.equals("")||s==null){
                return false;
            }
        } catch (Exception e) {
            return false;
        }

        return true;
    }
}
